package com.sakura.hk.word.config;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * word的配置
 * @Author: 贺坤
 * @Date: 2021/10/14 10:33
 */
@Configuration
public class WordConfig {
    /**
     * 运行是时候显示word窗口
     */
    @Value("${word.visible}")
    private Boolean visible = false;

    /**
     * word 程序对象本身
     * @return
     */
    @Bean
    public ActiveXComponent word() {
        ActiveXComponent  word = new ActiveXComponent("Word.Application");
        word.setProperty("Visible", new Variant(visible));
        return word;
    }

    /**
     * 获取所有文件的集合
     * @param word
     * @return
     */
    @Bean
    public Dispatch documents(ActiveXComponent word){
        return  word.getProperty("Documents").toDispatch();
    }

}
